package com.playball.lottery.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.playball.lottery.R;
import com.playball.lottery.bean.APPOfAdvertisingBean;
import com.playball.lottery.util.province.GlobalUtils;

import java.util.List;

/**广告位适配器
 * Created by Administrator on 2017/3/15.
 */

public class BarberGalleryAdapter extends BaseAdapter {

    private Context context;
    private List<APPOfAdvertisingBean> lists;
    @SuppressWarnings("unused")
    private Gallery gallery;

    public  BarberGalleryAdapter(Context cnt, List<APPOfAdvertisingBean> list, Gallery gallery) {
        this.context = cnt;
        this.lists = list;
        this.gallery = gallery;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public Object getItem(int arg0) {
        return lists.get(arg0 % lists.size());
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup arg2) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.header_gallery_item, arg2,false);
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.home_img);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        int w = GlobalUtils.getWidthPixels(context);
        int h = (int) (w * 0.35);
        android.widget.FrameLayout.LayoutParams params = new android.widget.FrameLayout.LayoutParams(w, h);
        viewHolder.imageView.setLayoutParams(params);


        ImageLoader.getInstance().displayImage(lists.get(position % lists.size()).getImgPath(), viewHolder.imageView,GlobalUtils.getDisplayImageOptions());


        return convertView;
    }

    public class ViewHolder {
        ImageView imageView;
    }


}
